<?php
if(!defined('DCS_ROOT')) {exit('Access Denied');}

class photosModel {

	var $DB;

	function photosModel ( $DB ){
		$this->DB = $DB;
	}

	function getList($condition) {
		$sql = "SELECT * FROM {$condition['table']} ";
		$tmp = "";
		if (!empty($condition['condition'])) {
			$tmp .= "WHERE {$condition['condition']} ";
		} 
		if (!empty($condition['order'])) {
			$tmp .= " ORDER BY {$condition['order']} DESC ";
		} 
		if (!empty($condition['page']) && !empty($condition['rows'])) {
			$start = ($condition['page'] - 1) * $condition['rows'];
			$tmp .= "LIMIT " . $start . ", " . $condition['rows'];
		} 
		$sql .= $tmp;
		$this->DB->query($sql);
		return $this->DB->fetchAll();
	}

	function total($condition) {
		$sql = "SELECT count(*) AS total FROM {$condition['table']} ";
		$tmp = "";
		if (!empty($condition['condition'])) {
			$tmp .= "WHERE {$condition['condition']} ";
		} 
		if (!empty($condition['order'])) {
			$tmp .= " ORDER BY {$condition['order']} DESC ";
		} 
		$sql .= $tmp;
		$this->DB->query($sql);
		$this->DB->fetchRow();
		return $this->DB->getValue("total");
	}

	function getMovie($id){
		$sql = "SELECT * FROM movie WHERE id = '$id' ";
		$this->DB->query($sql);
		return $this->DB->fetchRow();	
	}

	function getPhoto($id){
		$sql = "SELECT * FROM movie_photo WHERE id = '$id' ";
		$this->DB->query($sql);
		return $this->DB->fetchRow();	
	}

	function getUser($uid){
		$sql = "SELECT uid,username,avatars FROM member WHERE uid = '$uid' ";
		$this->DB->query($sql);
		return $this->DB->fetchRow();	
	}

	function getMembers($uids){
		$sql = "SELECT uid,username,avatars FROM member WHERE uid IN($uids) ";
		$this->DB->query($sql);
		return $this->DB->fetchAll();	
	}


}
?>
